﻿using System;
using System.Collections.Generic;
using System.Text;
using com.huigo.Framework.ServiceUtils;
using com.huigo.Framework.Passport;

namespace com.huigo.B2B.Web
{
    public partial class ProductList : System.Web.UI.Page
    {
        private int pageIndex
        {
            get
            {
                return com.loto.Common.TypeParse.StrToInt(Request.QueryString["page"], 1);
            }
        }

        private int productId
        {
            get
            {
                int p = int.MinValue;
                if (int.TryParse(Request.QueryString["pid"], out p))
                    return p;
                else
                    return 1;
            }
        }
        public string insType = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (productId == 2)
            {
                insType = "旅游意外险";
            }
            if (productId == 1)
            {
                insType = "航空意外险";
            }
        }

        protected void pageInfo_PageChanged(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindData();
        }

        protected void BindData()
        {
            List<RequestFuncParams> argList = new List<RequestFuncParams>();
            argList.Add(new RequestFuncParams("proType", productId.ToString()));
            argList.Add(new RequestFuncParams("pageSize", pageInfo.PageSize.ToString()));
            argList.Add(new RequestFuncParams("pageIndex", pageIndex.ToString()));
            BaseService baseService = new BaseService();
            ParserXml parser = baseService.RequestEntryService(Dict.ERequestFunc.FORE_GET_PRODUCT_LIST, argList);

            if (parser != null && parser.RowsCount > 0)
            {
                pageInfo.RecordCount = Convert.ToInt16(parser["RecordCount", 0]);
                pageInfo.CurrentPageIndex = pageIndex;
                pageInfo.PageURLFormat = GetPagerUrl();
                rptProduct.DataSource = parser.ModelList;
                rptProduct.DataBind();
            }
        }

        private string GetPagerUrl()
        {
            string url = "ProductList.aspx?";
            url += "page={0}";
            return url;
        }

        public string ShowRealPrice(string strPrice, string productId)
        {
            string price = string.Empty;
            if (!CustPassport.ChkCookieLogin())
            {
                price = "<a class=\"btn\" href=\"Login.aspx?toUrl=" + com.loto.Common.Utils.UrlEncode(Request.Url.AbsoluteUri) + "\">登录后查看返利后价格 &raquo;</a>";
            }
            else
                price = "结算价：<span class=\"red bold\" style=\"font-size: 16px;\">" + strPrice + "</span><br/><br /><a  class=\"btn\" href=\"ProductDetail.aspx?id=" + productId + "\">点击购买</a>";
            return price;
        }
    }
}
